package com.example.controller;

import com.example.pojo.Emp;
import com.example.pojo.PageData;
import com.example.pojo.Result;
import com.example.service.EmpService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;

@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
   public EmpService empService;


    //分页查询
    @GetMapping
    public Result page(String name, Integer gender , @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate begin ,
                       @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end, Integer page, Integer pageSize){
      PageData p1= empService.page(name,gender,begin,end,page,pageSize);
      return new Result().success(p1);
    }


    //删除员工
    @DeleteMapping("/{ids}")
    public Result delect(@PathVariable List<Integer> ids){
        empService.delect(ids);
        return new Result().success();
    }

    //新建员工
    @PostMapping
    public Result insert( @RequestBody Emp emp){
        empService.insert(emp);

        return new Result().success();
        }


    //根据id查询员工信息
        @GetMapping("/{id}")
    public Result select(@PathVariable Integer id){
       Emp emp =  empService.select(id);
        return Result.success(emp);
    }


    //修改员工信息
    @PutMapping
    public Result updata(@RequestBody Emp emp){
            empService.updata(emp);

        return Result.success();
    }

}